﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using SmartMad.Ads.WindowsPhone7.WPF;

namespace LunchRoller
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Set the data context of the listbox control to the sample data
            DataContext = App.ViewModel;
            this.Loaded += new RoutedEventHandler(MainPage_Loaded);

            App.BindCommand(App.ViewModel.AddItemCommand, ApplicationBar.Buttons[0] as ApplicationBarIconButton);
            App.BindCommand(App.ViewModel.SaveAllItemsCommand, ApplicationBar.Buttons[1] as ApplicationBarIconButton);
            App.BindCommand(App.ViewModel.ImportExportCommand, ApplicationBar.Buttons[2] as ApplicationBarIconButton);
            App.ViewModel.PropertyChanged += (o, e) =>
            {
                if (e.PropertyName == "SelectedIndex")
                {


                    if (App.ViewModel.SelectedIndex == 3)
                    {
                        if (History.Items.Count > 0)
                            History.ScrollIntoView(History.Items[History.Items.Count - 1]);

                    }
                }
            };


            var networkIsAvailable = Microsoft.Phone.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
            if (networkIsAvailable && App.ViewModel.IsTrial)
            {
                //      <SmartMad_Ads_WindowsPhone7_WPF:AdView AdSize="AdSize480x72"   AdPositionID="90009409" AdAnimation="AdAnimationRandom" IsDebugMode="False"> </SmartMad_Ads_WindowsPhone7_WPF:AdView>
                var ad = new AdView()
                {
                    AdPositionID = "90009409",
                    AdAnimation = AdAnimationType.AdAnimationNone,
                    AdSize = AdSizeType.AdSize480x72,
                   
                    IsDebugMode = false
                };


                AdConatiner.Children.Add(ad);
            }
            
            

        }

     

        // Load data for the ViewModel Items
        private void MainPage_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Panorama_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            App.ViewModel.SelectedIndex = (sender as Panorama).SelectedIndex;
        }


    }
}